package com.zh.springcloud.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Map;

/**
 * @Description:
 * @ClassName TestDirectListener
 * @date: 2021.08.20 11:14
 * @Author: zhanghang
 */
@Component
public class TestDirectListener {

	@RabbitListener(queues = "test-direct-queue")
//	@RabbitListener(containerFactory = "singleListenerContainer", queues = {"kinson2"})
	public void receiver5(Message msg, Channel channel) throws IOException, InterruptedException {
		//打印数据
		String message = new String(msg.getBody(), StandardCharsets.UTF_8);
		System.out.println("队列1消费消息{}"+message);
//		channel.basicReject(msg.getMessageProperties().getDeliveryTag(), false);
		channel.basicAck(msg.getMessageProperties().getDeliveryTag(),true);
	}
}
